from django.db import models


class User(models.Model):
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=120)
    level = models.IntegerField(default=1)


class Goods(models.Model):
    name = models.CharField(max_length=20)
    price = models.IntegerField('价格')
    stock = models.IntegerField('库存')


class Coupon(models.Model):
    sn = models.CharField(max_length=20)
    title = models.CharField(max_length=20)
    max = models.IntegerField()
    discount = models.IntegerField()


class Cart(models.Model):
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    num = models.IntegerField()


class UserCoupon(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    coupon = models.ForeignKey(Coupon, on_delete=models.CASCADE)


class Goods(models.Model):
    name = models.CharField(max_length=20)
